import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class TestDemo12 {
    public class MyArrayList<E>{
        private E[]array;
        private int size;
        //.......


    }
    public static void main (String[]args){
        Collection<String>collection=new ArrayList<>();
        collection.add("hello");
        collection.add("hello2");
        //System.out.println(collection);
        Object[] objects=collection.toArray();
        System.out.println(Arrays.toString(objects));
    }
    //判断是否是回文结构
    public boolean chkPalindrome(ListNode head) {
        if (head == null) {
            return false;
        }
        ListNode fast = head;
        ListNode slow = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        ListNode cur = slow.next;
        while (cur != null) {//对后面的数字开始反转
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }
        while (slow != head) {
            if (slow.val != head.val) {
                return false;
            }
            if (head == slow) {//奇数个数的回文结构
                break;
            }
            if (slow == head.next) {//偶数个数的回文结构，不能是slow.next=head
                break;              //因为访问不到
            }
            head = head.next;
            slow = slow.next;
        }
        return true;
    }//杨辉三角

    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        ret.add(list1);
        for (int i = 1; i < numRows; i++) {
            List<Integer> list = new ArrayList<>();
            list.add(1);
            List<Integer> prev = ret.get(i - 1);
            for (int j = 1; j < i; j++) {
                int nums = prev.get(j) + prev.get(j - 1);
                list.add(nums);
            }
            list.add(1);
            ret.add(list);
        }
        return ret;
    }

    public int findJudge(int n, int[][] trust) {
        int[] trustValus = new int[n+1];
        for (int[]t:trust){
            trustValus[t[0]]--;
            trustValus[t[1]]++;
        }
        for(int i=1;i<n;i++){
            if(trustValus[i]==n-1){
                return i;
            }
        }return -1;
    }
}